
package de.unihannover.se.restlab.microblog_client.models;

import java.util.Date;

import javax.xml.bind.annotation.*;

@XmlRootElement(name = "message")
@XmlAccessorType(XmlAccessType.FIELD)
public class Message {

	@XmlElement
	private Integer id;
	@XmlElement
	private String content;
	@XmlElement
	private Date createdAt;
	@XmlElement
	private User user;

	@XmlElementRef
	private Link self;

	// @XmlAttribute
	// private String ref;

	@XmlElement
	private Integer parentId; // != 0 dann reblogged

	public Link getSelf () {
		return self;
	}

	public void setSelf (Link self) {
		this.self = self;
	}

	public Message () {
	}

	public Message (Integer id, User user, String content, Integer parentId) {
		this(id, user, content);
		this.parentId = parentId;
	}

	public Message (Integer id, User user, String content) {
		super();
		this.id = id;
		this.parentId = -1;
		this.user = user;
		this.content = content;
		this.createdAt = new Date();
		// this.ref = "http://localhost:8080/microblog/messages/" + id;
	}

	public String getContent () {
		return content;
	}

	public void setContent (String content) {
		this.content = content;
	}

	public Integer getId () {
		return id;
	}

	public Date getCreatedAt () {
		return createdAt;
	}

	public User getUser () {
		return user;
	}

	public void setId (Integer id) {
		this.id = id;
	}

	public void setCreatedAt (Date createdAt) {
		this.createdAt = createdAt;
	}

	public void setUser (User user) {
		this.user = user;
	}

	public Integer getParentId () {
		return parentId;
	}

	public void setParentId (Integer parentId) {
		this.parentId = parentId;
	}

	@Override
	public String toString () {
		return "Message [id=" + id + ", content=" + content + ", createdAt=" + createdAt + ", user=" + user.getName()
			+ ", parentId=" + parentId + "]" + ((parentId != null && parentId != -1) ? " (reblogged)" : "");
	}

}
